package com.lonwin.inspectionmanagement.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.app.utils.AppUtil;
import com.lonwin.inspectionmanagement.app.utils.TimeUtils;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.SortOutBean;
import com.lonwin.inspectionmanagement.mvp.ui.activity.CreatPointRecordActivity;
import com.lonwin.inspectionmanagement.mvp.ui.activity.LookPatrolRecordActivity;

import java.util.List;

public class SortOutRecordAdapter extends BaseQuickAdapter<SortOutBean.DataBean.RecordsBean,BaseViewHolder> {
    public SortOutRecordAdapter(@Nullable List<SortOutBean.DataBean.RecordsBean> data) {
        super(R.layout.sortout_record_item,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SortOutBean.DataBean.RecordsBean item) {
        helper.setText(R.id.sortout_record_item_title,item.getXcgcjl().getGroupnm()!=null?item.getXcgcjl().getGroupnm():"").setText(R.id.sortout_record_item_time,"（"+TimeUtils.dateForMonthDay(item.getXcgcjl().getSystm())+"巡查记录）");
        helper.setText(R.id.sortout_record_item_jlwts,"记录问题数："+item.getXcgcjl().getQuestcount()+"个")
                .setText(R.id.sortout_record_item_jlgjs,"记录轨迹数："+item.getXcgcjl().getPathcount()+"条");
        if (item.getQuestTempDtos()!=null&&!item.getQuestTempDtos().isEmpty())
        {
            RecyclerView recyclerView1=helper.<RecyclerView>getView(R.id.sortout_record_item_RecyclerView1);
            recyclerView1.setLayoutManager(new LinearLayoutManager(mContext));
            SortOutRecordItemItem1Adapter adapter1=new SortOutRecordItemItem1Adapter(item.getQuestTempDtos());
            adapter1.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
            recyclerView1.setAdapter(adapter1);
        }
        if (item.getXcpathTemps()!=null&&!item.getXcpathTemps().isEmpty())
        {
            RecyclerView recyclerView2=helper.<RecyclerView>getView(R.id.sortout_record_item_RecyclerView2);
            recyclerView2.setLayoutManager(new LinearLayoutManager(mContext));
            SortOutRecordItemItem2Adapter adapter2=new SortOutRecordItemItem2Adapter(item.getXcpathTemps());
            adapter2.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
            recyclerView2.setAdapter(adapter2);
        }
        if (item.getXcjlb()==null)
        {
            helper.<LinearLayout>getView(R.id.sortout_record_item_xcjlb_lay).setVisibility(View.GONE);
            helper.<View>getView(R.id.sortout_record_item_xcjlb_line).setVisibility(View.GONE);

        }else {
            helper.<View>getView(R.id.sortout_record_item_xcjlb_line).setVisibility(View.VISIBLE);
            helper.<LinearLayout>getView(R.id.sortout_record_item_xcjlb_lay).setVisibility(View.VISIBLE);
           helper.setText(R.id.sortout_record_item_xcjlb_title,item.getXcjlb().getTitle())
                   .setText(R.id.sortout_record_item_xcjlb_statue,AppUtil.getStrStatus(item.getXcjlb().getStepstatus()))
                   .setText(R.id.sortout_record_item_xcjlb_time,TimeUtils.dateForStr(item.getXcjlb().getSystm()));

        }

        helper.<TextView>getView(R.id.sortout_record_item_xcjlb_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlb().getXcjlbid(),LookPatrolRecordActivity.Type.LOOK,"查看巡查记录表");
            }
        });
    }
}
